package org.ciallo.simplemusicplayer.viewmodel;

import android.app.Application;
import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import org.ciallo.simplemusicplayer.data.model.Song;
import org.ciallo.simplemusicplayer.data.repository.SongRepository;

import java.util.List;

/**
 * @author Jukomu
 * @Description: 管理最近播放歌曲列表的 ViewModel
 * @Package: org.ciallo.simplemusicplayer.data.model
 * @Project: SimpleMusicPlayer
 * @name: PlaylistSongCrossRef
 * @Date: 2025/5/30-00:58
 * @Filename: PlaylistSongCrossRef
 */
public class RecentPlayViewModel extends AndroidViewModel {
    private final SongRepository songRepository;

    /**
     * LiveData，包含最近播放的歌曲列表（完整的Song对象）。
     */
    public final LiveData<List<Song>> recentlyPlayedSongs;

    public RecentPlayViewModel(@NonNull Application application) {
        super(application);
        songRepository = new SongRepository(application);
        recentlyPlayedSongs = songRepository.getRecentlyPlayedSongsWithDetails();
    }

    /**
     * 获取最近播放的歌曲列表。
     * @return LiveData 包装的歌曲列表。
     */
    public LiveData<List<Song>> getRecentlyPlayedSongs() {
        return recentlyPlayedSongs;
    }

    /**
     * 清空所有最近播放记录。
     */
    public void clearAllRecentPlays() {
        songRepository.clearAllRecentPlays();
        // LiveData 会自动更新为空列表
    }
}
